﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Plateformeur.GameEntities;
using Microsoft.Xna.Framework;

namespace Plateformeur.Engine
{
    class PlayerController : IInput
    {
        public void Update(ControllerGameObject pTarget, GameTime pTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                if(((Player)pTarget).isGrounded())
                {
                    ((Player)pTarget).setVelocity(new Vector2(((Player)pTarget).getVelocity().X, -20));
                    ((Player)pTarget).Walk();
                }

            }else if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                if (((Player)pTarget).isGrounded())
                {
                    if (pTarget.Position.X < 1020)
                    {
                        ((Player)pTarget).setVelocity(new Vector2(10, 0));
                    }
                    ((Player)pTarget).Walk();
                }

            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                if (((Player)pTarget).isGrounded())
                {
                    if (pTarget.Position.X > 10)
                    {
                        ((Player)pTarget).setVelocity(new Vector2(-10, 0));
                    }
                    ((Player)pTarget).Walk();
                }

            }
            else if (Keyboard.GetState().IsKeyDown(Keys.LeftControl))
            {
                ((Player)pTarget).Shoot();
            }
            else
            {
                ((Player)pTarget).setVelocity(new Vector2(0, ((Player)pTarget).getVelocity().Y));
                ((Player)pTarget).Idle();
            }
        }
    }
}
